/*
 *
 *
 */

#ifndef GKT_NETWORK_H_
#define GKT_NETWORK_H_

#include "gkt_types.h"

#ifdef __cplusplus
extern "C" {
#endif

#if !defined(GKT_CONFIG_BACKBOARD_ENABLE) || !GKT_CONFIG_BACKBOARD_ENABLE
#define GKT_NETWORK_LOCATION	GKT_MODULE_LOC_FRONTBOARD
#elif defined(GKT_CONFIG_NETWORK_LOCATION)
#define GKT_NETWORK_LOCATION \
	GKT_MODULE_LOCATION(GKT_CONFIG_NETWORK_LOCATION)
#else
#define GKT_NETWORK_LOCATION GKT_MODULE_LOC_BACKBOARD
#endif

/* network time sync cycle */
#define GKT_NETWOTK_TIME_SYNC_NONE		0
#define GKT_NETWOTK_TIME_SYNC_WAKEUP	1
#define GKT_NETWOTK_TIME_SYNC_DAILY		2	/* default */
#define GKT_NETWOTK_TIME_SYNC_WEEKLY	3
#ifdef GKT_CONFIG_NETWORK_SYNC_CYCLE
#define GKT_NETWORK_SYNC_CYCLE_L2(_cycle)	\
	GKT_NETWOTK_TIME_SYNC_##_cycle
#define GKT_NETWORK_SYNC_CYCLE_L1(_cycle)	\
	GKT_NETWORK_SYNC_CYCLE_L2(_cycle)
#define GKT_NETWORK_SYNC_CYCLE	\
	GKT_NETWORK_SYNC_CYCLE_L1(GKT_CONFIG_NETWORK_SYNC_CYCLE)
#else
#define GKT_NETWORK_SYNC_CYCLE	GKT_NETWOTK_TIME_SYNC_DAILY
#endif

#if defined(GKT_CONFIG_NETWORK_CONNECT_TIMEOUT_SEC)
#define GKT_NETWORK_CONNECT_TIMEOUT_SEC \
	GKT_CONFIG_NETWORK_CONNECT_TIMEOUT_SEC
#else
#define GKT_NETWORK_CONNECT_TIMEOUT_SEC 180
#endif

#if defined(GKT_CONFIG_NETWORK_FIRMWARE_UPGRADE_TIMEOUT_SEC)
#define GKT_NETWORK_FIRMWARE_UPGRADE_TIMEOUT_SEC \
	GKT_CONFIG_NETWORK_FIRMWARE_UPGRADE_TIMEOUT_SEC
#else 
#define GKT_NETWORK_FIRMWARE_UPGRADE_TIMEOUT_SEC 300
#endif

#if defined(GKT_CONFIG_NETWORK_SELF_TEST_TIMEOUT_SEC)
#define GKT_NETWORK_SELF_TEST_TIMEOUT_SEC \
	GKT_CONFIG_NETWORK_SELF_TEST_TIMEOUT_SEC
#else 
#define GKT_NETWORK_SELF_TEST_TIMEOUT_SEC 30
#endif

#define GKT_NETWORK_DEFAULT_TIMEOUT_SEC 3

typedef enum {
	GKT_NETWORK_CONNECT_ST_POWER_DONW = 0,
	GKT_NETWORK_CONNECT_ST_UNCONFIG,
	GKT_NETWORK_CONNECT_ST_CONFIG,
	GKT_NETWORK_CONNECT_ST_CONNECT_AP,
	GKT_NETWORK_CONNECT_ST_CONNECTED,
	GKT_NETWORK_CONNECT_ST_MAX
}gkt_network_connect_st_e;

typedef enum {
	GKT_NETWORK_RUNNING_ST_CONNECTING = 0,
	GKT_NETWORK_RUNNING_ST_CONNECTED,
	GKT_NETWORK_RUNNING_ST_CONNECT_FAILED,
	GKT_NETWORK_RUNNING_ST_CONNECT_CANCELED,
	GKT_NETWORK_RUNNING_ST_CONNECT_CANCEL_FORBID,
	GKT_NETWORK_RUNNING_ST_CONNECT_CANCEL_FAILED,

	GKT_NETWORK_RUNNING_ST_UPGRADING,
	GKT_NETWORK_RUNNING_ST_UPGRADED,
	GKT_NETWORK_RUNNING_ST_UPGRADE_FAILED,
	GKT_NETWORK_RUNNING_ST_UPGRADE_CANCELED,
	GKT_NETWORK_RUNNING_ST_UPGRADE_CANCEL_FORBID,
	GKT_NETWORK_RUNNING_ST_UPGRADE_CANCEL_FAILED,

	GKT_NETWORK_RUNNING_ST_TESTING,
	GKT_NETWORK_RUNNING_ST_TEST_COMPLETE,
	GKT_NETWORK_RUNNING_ST_TEST_FAILED,

	GKT_NETWORK_RUNNING_ST_MAX,
}gkt_network_running_status_e;

/* network notify type */
typedef enum {
	GKT_NETWORK_NOTIFY_TYPE_COMMON_STATUS = 0,
	GKT_NETWORK_NOTIFY_TYPE_RUNNING_STATUS,
	GKT_NETWORK_NOTIFY_TYPE_TIME_SYNC,
	GKT_NETWORK_NOTIFY_TYPE_UPGRADE_PROGERSS,
	GKT_NETWORK_NOTIFY_TYPE_REMOTE_UNLOCK,
	GKT_NETWORK_NOTIFY_TYPE_MAX
} gkt_network_notify_type_e;

/*
 * @function  - gkt_door_notify_fn
 */
int gkt_network_init(void);

typedef void (*gkt_network_notify_fn)(uint32_t type, uint32_t data);
void gkt_network_register_notify(gkt_network_notify_fn notify);

int gkt_network_is_connected(void);
void gkt_network_set_sync_time_enable(uint32_t sync_time_enable);
/* time sync */
int gkt_network_time_sync(void);
int gkt_network_get_status_request(void);
uint32_t gkt_network_get_status(void);
int gkt_network_connect(void);
int gkt_network_connect_cancel(void);
int gkt_network_reset(void);
int gkt_network_firmware_upgrade(void);
int gkt_network_firmware_upgrade_cancel(void);
int gkt_network_self_test(void);
int gkt_network_aging_test(void);

typedef enum {
	GKT_NETWORK_MESSAGE_TYPE_TAMPER,
	GKT_NETWORK_MESSAGE_TYPE_FORCE_OPEN_DOOR,
	
	GKT_NETWORK_MESSAGE_TYPE_FREEZE_FINGERPRINT,
	GKT_NETWORK_MESSAGE_TYPE_FREEZE_PASSWORD,
	GKT_NETWORK_MESSAGE_TYPE_FREEZE_CARD,
	GKT_NETWORK_MESSAGE_TYPE_FREEZE_KEY,
	GKT_NETWORK_MESSAGE_TYPE_FREEZE_REMOTE,
	GKT_NETWORK_MESSAGE_TYPE_FREEZE_ANY,
	
	GKT_NETWORK_MESSAGE_TYPE_FAILED_ALARM_FINGERPRINT,
	GKT_NETWORK_MESSAGE_TYPE_FAILED_ALARM_PASSWORD,
	GKT_NETWORK_MESSAGE_TYPE_FAILED_ALARM_CARD,
	GKT_NETWORK_MESSAGE_TYPE_FAILED_ALARM_FACE,
	GKT_NETWORK_MESSAGE_TYPE_FAILED_ALARM_ANY,
	
	GKT_NETWORK_MESSAGE_TYPE_ALARM_COERCE,
	GKT_NETWORK_MESSAGE_TYPE_ALARM_STRANGER_STAY,
	GKT_NETWORK_MESSAGE_TYPE_ALARM_SYSTEM_LOCK_IN,
	
	GKT_NETWORK_MESSAGE_TYPE_LOW_BATTERY,

	GKT_NETWORK_MESSAGE_TYPE_MAX
} gkt_network_message_type_e;
int gkt_network_message_upload(gkt_network_message_type_e type);

typedef enum {
	GKT_NETWORK_UNLOCK_TYPE_VERIFY = 0,
	GKT_NETWORK_UNLOCK_TYPE_KEY,
	GKT_NETWORK_UNLOCK_TYPE_REMOTE,
	GKT_NETWORK_UNLOCK_TYPE_MAX
} gkt_network_unlock_type_e;
int gkt_network_unlock_record(gkt_network_unlock_type_e type,
				uint32_t user_id_nums, uint32_t *user_ids);


/*
 * @function gkt_network_remote_unlock_request
 * @brief    request remote unlock
 * @paras
 *   action   [in] 1-request, 0-cancel previous request
 * @return
 *   GKT_EINPROCESS
 */
int gkt_network_remote_unlock_request(int action);

#ifdef __cplusplus
}
#endif

#endif	/* GKT_NETWORK_H */

